package com.ruoyi.project.digital.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.digital.domain.UserBack;
import com.ruoyi.project.digital.service.IUserBackService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户背景Controller
 * 
 * @author ruoyi
 * @date 2023-12-03
 */
@RestController
@RequestMapping("/digital/UserBack")
public class UserBackController extends BaseController
{
    @Autowired
    private IUserBackService userBackService;

    /**
     * 查询用户背景列表
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserBack userBack)
    {
        startPage();
        List<UserBack> list = userBackService.selectUserBackList(userBack);
        return getDataTable(list);
    }

    /**
     * 导出用户背景列表
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:export')")
    @Log(title = "用户背景", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserBack userBack)
    {
        List<UserBack> list = userBackService.selectUserBackList(userBack);
        ExcelUtil<UserBack> util = new ExcelUtil<UserBack>(UserBack.class);
        return util.exportExcel(list, "UserBack");
    }

    /**
     * 获取用户背景详细信息
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userBackService.selectUserBackById(id));
    }

    /**
     * 新增用户背景
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:add')")
    @Log(title = "用户背景", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserBack userBack)
    {
        return toAjax(userBackService.insertUserBack(userBack));
    }

    /**
     * 修改用户背景
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:edit')")
    @Log(title = "用户背景", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserBack userBack)
    {
        return toAjax(userBackService.updateUserBack(userBack));
    }

    /**
     * 删除用户背景
     */
    @PreAuthorize("@ss.hasPermi('digital:UserBack:remove')")
    @Log(title = "用户背景", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userBackService.deleteUserBackByIds(ids));
    }
}
